//
//  File.swift
//  EVOP
//
//  Created by LC_WJH on 2017/9/11.
//  Copyright © 2017年 gmc. All rights reserved.
//

import Foundation

//快速点击阻碍 - 用于在快速点击时候阻碍用户行为,防止app卡死
public class FastClickBlockHandler:NSObject{
    
    
    fileprivate static var  _fcdStatic:FastClickBlockHandler!;
    private var clear:Bool = true;
    public typealias DCB = ()->Void;
    
    public static var deadSec:Double = 0.5
    
    public static func block(ifOK:DCB?){
        FastClickBlockHandler.blockFor(sec:FastClickBlockHandler.deadSec,ifOK:ifOK);
    }
    
    
    public static func blockFor(sec:Double,ifOK:DCB?){
        
        if _fcdStatic == nil {
            _fcdStatic = FastClickBlockHandler();
        }
        
        if _fcdStatic.clear {
            ifOK?();
            
            _fcdStatic.clear = false;
            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + sec, execute: {
                FastClickBlockHandler._fcdStatic?.clear = true;
            });
            
        }
        
        
    }
    
    
    
    
}
